import 'package:distribution_mall_flutter/constant/image_constant.dart';
import 'package:distribution_mall_flutter/pages/home/home_provider.dart';
import 'package:distribution_mall_flutter/provider/common/tab.dart';
import 'package:distribution_mall_flutter/utils/image_loader.dart';
import 'package:distribution_mall_flutter/widgets/icon_button.dart';
import 'package:flutter/material.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';

class HomeAppbar extends ConsumerWidget implements PreferredSizeWidget {
  final BuildContext context;

  const HomeAppbar({super.key, required this.context});

  @override
  Widget build(BuildContext context, WidgetRef ref) {
    final tabModal = ref.watch(tabProvider);
    var isTab = ref.watch(homeIsTabProvider);
    return AppBar(
      leadingWidth: 116,
      // toolbarHeight: 58,
      scrolledUnderElevation: 0,
      backgroundColor:
          isTab == true ? Colors.white : const Color(0xFFF5F6F8),
      leading: Padding(
        padding: const EdgeInsets.only(left: 16, top: 3),
        child: ImageLoader.imageAsset(ImageLocalConstant.epalTextLogo,
            fit: BoxFit.contain, width: 118.3, height: 38.2),
      ),
      actions: [
        Padding(
          padding: const EdgeInsets.only(right: 16),
          child: EPIconButton(
            width: 30,
            height: 30,
            onPressed: () async {
              if (Scaffold.of(context).isEndDrawerOpen) {
                Scaffold.of(context).closeEndDrawer();
              } else {
                Scaffold.of(context).openEndDrawer();
              }
            },
            icon: const Icon(
              Icons.notes,
              color: Color.fromRGBO(29, 27, 32, 1),
            ),
          ),
        )
      ],
    );
  }

  @override
  Size get preferredSize => const Size(double.infinity, kToolbarHeight);
}
